﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.InteropServices;
using System.IO;

namespace 会员卡管理系统
{
    public partial class Mainfrm : Form
    {
        bool ok1 = false;//系统首页是否按下
        bool ok2 = false;//住宿现状是否按下
        bool ok3 = false;//会员管理是否按下
        bool ok4 = false;//房间管理是否按下
        bool ok5 = false;//记录管理是否按下
        bool ok6 = false;//系统设置是否按下
        public HouseNow Housenow;//定义住宿情况变量
        public VipManage Vipmanage;//定义会员管理变量
        public HouseManage Housemanage;//定义房间管理变量
        public RecordManage Recordmanage;//定义记录管理变量
        public SysSet Sysset;//定义系统设置变量
        private bool windowCreate = true;//窗体是否已经后台运行
        public Mainfrm()
        {
            InitializeComponent();
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW); //API函数加载，实现窗体边框阴影效果
            this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
        }
        Vipclass.tb_viphouseinfo tbVip = new Vipclass.tb_viphouseinfo();//相关参数
        Vipclass.tbVipHouseMenthod tbVipMenthod = new Vipclass.tbVipHouseMenthod();//相关操作处理 
        #region 窗体边框阴影效果变量申明

        const int CS_DropSHADOW = 0x20000;
        const int GCL_STYLE = (-26);
        //声明Win32 API
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);

        #endregion
        #region 窗体拖动代码
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HTCAPTION = 0x2;

        [DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

        [DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
        }
        #endregion
        private void Mainfrm_Load(object sender, EventArgs e)
        {
            ok1 = true;
            //Housenow = new HouseNow();//给住宿情况窗体赋值
            //Vipmanage = new VipManage();//给会员管理窗体赋值
            //Housemanage = new HouseManage();//给房间管理窗体赋值
            //Recordmanage = new RecordManage();//给记录管理窗体赋值
            Sysset = new SysSet();//给系统设置窗体赋值
        }

        /// <summary>
        /// 完全退出系统退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("程序正在运行，是否退出？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                notifyIcon1.Visible = false;//后台图标隐藏
                System.Environment.Exit(System.Environment.ExitCode);
                this.Dispose();
                this.Close();
            }
            else
            {
                
            }
        }
        /// <summary>
        /// 退出按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_MouseEnter(object sender, EventArgs e)
        {
            btnExit.BackgroundImage = Properties.Resources.首页退出按钮红色;
        }
        /// <summary>
        /// 退出按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnExit_MouseLeave(object sender, EventArgs e)
        {
            btnExit.BackgroundImage = Properties.Resources.首页退出按钮白色;
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 显示系统时间事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            labTime.Text = System.DateTime.Now.ToLongDateString()+ System.DateTime.Now.ToLongTimeString();
        }
        /// <summary>
        /// 帮助按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            Helpfrm help = new Helpfrm();
            help.Show();
        }
        /// <summary>
        /// 帮助按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_MouseEnter(object sender, EventArgs e)
        {
            button1.BackgroundImage = Properties.Resources.首页帮助按钮蓝色;
        }
        /// <summary>
        /// 帮助按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_MouseLeave(object sender, EventArgs e)
        {
            button1.BackgroundImage = Properties.Resources.首页帮助按钮白色1;
        }
        /// <summary>
        /// 后台运行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.Visible == true)
            {
                this.Hide();
            }
            else
            {
                this.Visible = true;
                this.WindowState = FormWindowState.Normal;
                this.BringToFront();
                windowCreate = true;
            }
        }
        /// <summary>
        /// 后台运行按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click_1(object sender, EventArgs e)
        {
            if (notifyIcon1.Visible)
            {
                if (windowCreate)
                {
                    base.Visible = false;
                    windowCreate = false;
                }
                this.Hide();
                base.OnActivated(e);
            }
            else
            {
                MessageBox.Show("未开启后台运行功能，请到系统设置中开启！", "提示");
            }
        }


        /// <summary>
        /// 打开主面板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 打开主面板ToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (this.Visible == true)
            {
                //this.Hide();
            }
            else
            {
                this.Visible = true;
                this.WindowState = FormWindowState.Normal;
                this.BringToFront();
                windowCreate = true;
            }
        }

        private void 系统设置ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 状态栏右击退出事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("程序正在运行，是否退出？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                notifyIcon1.Visible = false;//后台图标隐藏
                System.Environment.Exit(System.Environment.ExitCode);
                this.Dispose();
                this.Close();
            }
            else
            {

            }
        }
        /// <summary>
        /// 后台事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnback_MouseEnter(object sender, EventArgs e)
        {
            btnback.BackgroundImage = Properties.Resources.主界面后台蓝色;
        }
        /// <summary>
        /// 后台事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnback_MouseLeave(object sender, EventArgs e)
        {
            btnback.BackgroundImage = Properties.Resources.主界面后台白色1;
        }
        /// <summary>
        /// 入住事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_MouseEnter(object sender, EventArgs e)
        {
            btnin.BackgroundImage = Properties.Resources.入住大;
        }

        private void btnin_MouseLeave(object sender, EventArgs e)
        {
            btnin.BackgroundImage = Properties.Resources.入住小;
        }
        /// <summary>
        /// 退房事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnout_MouseEnter(object sender, EventArgs e)
        {
            btnout.BackgroundImage = Properties.Resources.退房大;
        }

        private void btnout_MouseLeave(object sender, EventArgs e)
        {
            btnout.BackgroundImage = Properties.Resources.退房小;
        }

        private void btnfirst_MouseEnter(object sender, EventArgs e)
        {
            if(ok1==false)
            {
                btnfirst.BackgroundImage = Properties.Resources.主界面系统首页未选中粗体;
            }
        }

        private void btnfirst_MouseLeave(object sender, EventArgs e)
        {
            if (ok1 == false)
            {
                btnfirst.BackgroundImage = Properties.Resources.主界面系统首页未选中细体;
            }
        }

        private void btnfirst_Click(object sender, EventArgs e)
        {
            if(ok1==false)
            {
                panel1.Visible = false;
                btnfirst.BackgroundImage = Properties.Resources.主界面系统首页选中;
                btnHouseNow.BackgroundImage = Properties.Resources.主界面住宿现状未选中细体;
                btnVip.BackgroundImage = Properties.Resources.主界面会员管理未选中细体;
                btnHouse.BackgroundImage = Properties.Resources.主界面房间管理未选中细体;
                btnRecord.BackgroundImage = Properties.Resources.主界面记录管理未选中细体;
                btnSet.BackgroundImage = Properties.Resources.主界面系统设置未选中细体;
                ok1 = true;
                ok2 = false;
                ok3 = false;
                ok4 = false;
                ok5 = false;
                ok6 = false;
            }
        }

        private void btnHouseNow_MouseEnter(object sender, EventArgs e)
        {
            if (ok2 == false)
            {
                btnHouseNow.BackgroundImage = Properties.Resources.主界面住宿现状未选中粗体;
            }
        }

        private void btnHouseNow_MouseLeave(object sender, EventArgs e)
        {
            if (ok2 == false)
            {
                btnHouseNow.BackgroundImage = Properties.Resources.主界面住宿现状未选中细体;
            }
        }

        private void btnVip_MouseEnter(object sender, EventArgs e)
        {
            if (ok3 == false)
            {
                btnVip.BackgroundImage = Properties.Resources.主界面会员管理未选中粗体;
            }
        }

        private void btnVip_MouseLeave(object sender, EventArgs e)
        {
            if (ok3 == false)
            {
                btnVip.BackgroundImage = Properties.Resources.主界面会员管理未选中细体;
            }
        }

        private void btnHouse_MouseEnter(object sender, EventArgs e)
        {
            if(ok4==false)
            {
                btnHouse.BackgroundImage = Properties.Resources.主界面房间管理未选中粗体;
            }
        }

        private void btnHouse_MouseLeave(object sender, EventArgs e)
        {
            if (ok4 == false)
            {
                btnHouse.BackgroundImage = Properties.Resources.主界面房间管理未选中细体;
            }
        }

        private void btnRecord_MouseEnter(object sender, EventArgs e)
        {
            if(ok5==false)
            {
                btnRecord.BackgroundImage = Properties.Resources.主界面记录管理未选中粗体;
            }
        }

        private void btnRecord_MouseLeave(object sender, EventArgs e)
        {
            if (ok5 == false)
            {
                btnRecord.BackgroundImage = Properties.Resources.主界面记录管理未选中细体;
            }
        }

        private void btnSet_MouseEnter(object sender, EventArgs e)
        {
            if(ok6==false)
            {
                btnSet.BackgroundImage = Properties.Resources.主界面系统设置未选中粗体;
            }
        }

        private void btnSet_MouseLeave(object sender, EventArgs e)
        {
            if (ok6 == false)
            {
                btnSet.BackgroundImage = Properties.Resources.主界面系统设置未选中细体;
            }
        }

        private void btnHouseNow_Click(object sender, EventArgs e)
        {
            if (ok2 == false)
            {
                Housenow = new HouseNow();
                panel1.Visible = true;
                Housenow.Show();
                panel1.Controls.Clear();
                panel1.Controls.Add(Housenow);
                btnfirst.BackgroundImage = Properties.Resources.主界面系统首页未选中细体;
                btnHouseNow.BackgroundImage = Properties.Resources.主界面住宿现状选中;
                btnVip.BackgroundImage = Properties.Resources.主界面会员管理未选中细体;
                btnHouse.BackgroundImage = Properties.Resources.主界面房间管理未选中细体;
                btnRecord.BackgroundImage = Properties.Resources.主界面记录管理未选中细体;
                btnSet.BackgroundImage = Properties.Resources.主界面系统设置未选中细体;
                ok1 = false;
                ok2 = true;
                ok3 = false;
                ok4 = false;
                ok5 = false;
                ok6 = false;
            }
        }

        private void btnVip_Click(object sender, EventArgs e)
        {
            if (ok3 == false)
            {
                Vipmanage = new VipManage();
                panel1.Visible = true;
                Vipmanage.Show();
                panel1.Controls.Clear();
                panel1.Controls.Add(Vipmanage);
                btnfirst.BackgroundImage = Properties.Resources.主界面系统首页未选中细体;
                btnHouseNow.BackgroundImage = Properties.Resources.主界面住宿现状未选中细体;
                btnVip.BackgroundImage = Properties.Resources.主界面会员管理细体;
                btnHouse.BackgroundImage = Properties.Resources.主界面房间管理未选中细体;
                btnRecord.BackgroundImage = Properties.Resources.主界面记录管理未选中细体;
                btnSet.BackgroundImage = Properties.Resources.主界面系统设置未选中细体;
                ok1 = false;
                ok2 = false;
                ok3 = true;
                ok4 = false;
                ok5 = false;
                ok6 = false;
            }
        }

        private void btnHouse_Click(object sender, EventArgs e)
        {
            if (ok4 == false)
            {
                Housemanage = new HouseManage();
                panel1.Visible = true;
                Housemanage.Show();
                panel1.Controls.Clear();
                panel1.Controls.Add(Housemanage);
                btnfirst.BackgroundImage = Properties.Resources.主界面系统首页未选中细体;
                btnHouseNow.BackgroundImage = Properties.Resources.主界面住宿现状未选中细体;
                btnVip.BackgroundImage = Properties.Resources.主界面会员管理未选中细体;
                btnHouse.BackgroundImage = Properties.Resources.主界面房间管理选中;
                btnRecord.BackgroundImage = Properties.Resources.主界面记录管理未选中细体;
                btnSet.BackgroundImage = Properties.Resources.主界面系统设置未选中细体;
                ok1 = false;
                ok2 = false;
                ok3 = false;
                ok4 = true;
                ok5 = false;
                ok6 = false;
            }
        }

        private void btnRecord_Click(object sender, EventArgs e)
        {
            if (ok5 == false)
            {
                Recordmanage = new RecordManage();
                panel1.Visible = true;
                Recordmanage.Show();
                panel1.Controls.Clear();
                panel1.Controls.Add(Recordmanage);
                btnfirst.BackgroundImage = Properties.Resources.主界面系统首页未选中细体;
                btnHouseNow.BackgroundImage = Properties.Resources.主界面住宿现状未选中细体;
                btnVip.BackgroundImage = Properties.Resources.主界面会员管理未选中细体;
                btnHouse.BackgroundImage = Properties.Resources.主界面房间管理未选中细体;
                btnRecord.BackgroundImage = Properties.Resources.主界面记录管理选中;
                btnSet.BackgroundImage = Properties.Resources.主界面系统设置未选中细体;
                ok1 = false;
                ok2 = false;
                ok3 = false;
                ok4 = false;
                ok5 = true;
                ok6 = false;
            }
        }

        private void btnSet_Click(object sender, EventArgs e)
        {
            if (ok6 == false)
            {
                
                panel1.Visible = true;
                Sysset.Show();
                panel1.Controls.Clear();
                panel1.Controls.Add(Sysset);
                btnfirst.BackgroundImage = Properties.Resources.主界面系统首页未选中细体;
                btnHouseNow.BackgroundImage = Properties.Resources.主界面住宿现状未选中细体;
                btnVip.BackgroundImage = Properties.Resources.主界面会员管理未选中细体;
                btnHouse.BackgroundImage = Properties.Resources.主界面房间管理未选中细体;
                btnRecord.BackgroundImage = Properties.Resources.主界面记录管理未选中细体;
                btnSet.BackgroundImage = Properties.Resources.主界面系统设置选中;
                ok1 = false;
                ok2 = false;
                ok3 = false;
                ok4 = false;
                ok5 = false;
                ok6 = true;
            }
        }

        private void btnin_Click(object sender, EventArgs e)
        {
            Stayfrm stay = new Stayfrm();
            stay.ShowDialog();
        }

        private void btnout_Click(object sender, EventArgs e)
        {
            Leavefrm leave = new Leavefrm();
            leave.ShowDialog();
        }

        private void label2_Click_1(object sender, EventArgs e)
        {

        }

        private void Mainfrm_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
        }

        /// <summary>
        /// 添加会员模块
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void button1_Click(object sender, EventArgs e)
        //{
        //    //OleDbConnection strConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "会员管理系统.mdb" + ";Persist Security Info=False");
        //    ////建立数据库引擎连接，注意数据表（后缀为.db）应放在DEBUG文件下
        //    //OleDbDataAdapter myda = new OleDbDataAdapter("select * from Vip_Table", strConnection);
        //    ////建立适配器，通过SQL语句去搜索数据库
        //    //DataSet myds = new DataSet();
        //    ////建立数据集
        //    //myda.Fill(myds, "Vip_Table");
        //    ////用FILL的方式将适配器已经连接好的数据表填充到数据集MYDS这张表
        //    //dataGridView1.DataSource = myds.Tables["Vip_Table"];

        //    tbVip.Strvipid = textBox1.Text;
        //    tbVip.Strvipname = textBox2.Text;
        //    tbVip.Strvipidcard = textBox3.Text;
        //    tbVip.Intgivetime = (int)numericUpDown1.Value;
        //    tbVip.Intalltime = (int)numericUpDown2.Value;
        //    if(tbVipMenthod.tbvipfoadd(tbVip)==1)
        //    {
        //        MessageBox.Show("VipAdd OK");

        //    }
        //    else
        //    {
        //        MessageBox.Show("VipAdd NO");
        //    }

        //}
        /// <summary>
        /// 修改会员模块
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void button2_Click(object sender, EventArgs e)
        //{
        //    tbVip.Strvipid = textBox1.Text;
        //    tbVip.Strvipname = textBox2.Text;
        //    tbVip.Strvipidcard = textBox3.Text;
        //    tbVip.Intgivetime = (int)numericUpDown1.Value;
        //    tbVip.Intalltime = (int)numericUpDown2.Value;
        //    if (tbVipMenthod.tbvipfoupdate(tbVip) == 1)
        //    {
        //        MessageBox.Show("VipUpdate OK");

        //    }
        //    else
        //    {
        //        MessageBox.Show("VipUpdate NO");
        //    }
        //}
        /// <summary>
        /// 删除会员模块
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void button3_Click(object sender, EventArgs e)
        //{
        //    if(tbVipMenthod.tbvipfodel(textBox1.Text)==1)
        //    {
        //        MessageBox.Show("VipDel OK");
        //    }
        //    else
        //    {
        //        MessageBox.Show("VipDel NO");
        //    }
        //}
        /// <summary>
        /// 添加房间模块
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void button4_Click(object sender, EventArgs e)
        //{
        //    tbVip.Strhouseid = textBox4.Text;
        //    if(tbVipMenthod.tbhousefoadd(tbVip)==1)
        //    {
        //        MessageBox.Show("HouseAdd OK");
        //    }
        //    else
        //    {
        //        MessageBox.Show("HouseAdd NO");
        //    }
        //}
        /// <summary>
        /// 修改房间模块
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void button5_Click(object sender, EventArgs e)
        //{
        //    tbVip.Strhouseid = textBox4.Text;
        //    tbVip.Bolhousestay = checkBox1.Checked;
        //    if (tbVipMenthod.tbhousefoupdate(tbVip) == 1)
        //    {
        //        MessageBox.Show("HouseUpadate OK");

        //    }
        //    else
        //    {
        //        MessageBox.Show("HouseUpdate NO");
        //    }

        //}
        /// <summary>
        /// 删除房间模块
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //private void button6_Click(object sender, EventArgs e)
        //{
        //    if(tbVipMenthod.tbhousefodel(textBox4.Text)==1)
        //    {
        //        MessageBox.Show("HouseDel OK");
        //    }
        //    else
        //    {
        //        MessageBox.Show("HouseDel No");
        //    }
        //}

    }
}
